﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.ViewModels.Controls
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Input;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.Services.Services;
    using Probel.Ldoc.ViewModels.Pages;
    using Probel.Mvvm.DataBinding;
    using Probel.Mvvm.Gui;

    public abstract class LocalisedItemViewModel : BaseViewModel
    {
        #region Fields

        protected readonly PatientEditorViewModel ParentViewModel;
        protected readonly PatientCardDto Patient;
        protected readonly IPatientService Service;

        private readonly ICommand createCommand;

        private string boxNumber;
        private string city;
        private string name;
        private string phone;
        private string postalCode;
        private string street;
        private string streetNumber;

        #endregion Fields

        #region Constructors

        public LocalisedItemViewModel(PatientEditorViewModel parent, IErrorService errorService, IPatientService service, PatientCardDto patient, bool isAsync = true)
            : base(errorService, isAsync)
        {
            this.ParentViewModel = parent;
            this.Service = service;
            this.Patient = patient;

            this.createCommand = new RelayCommand(this.Create, this.CanCreate);
        }

        #endregion Constructors

        #region Properties

        public string BoxNumber
        {
            get { return this.boxNumber; }
            set
            {
                this.boxNumber = value;
                this.OnPropertyChanged(() => BoxNumber);
            }
        }

        public string City
        {
            get { return this.city; }
            set
            {
                this.city = value;
                this.OnPropertyChanged(() => City);
            }
        }

        public ICommand CreateCommand
        {
            get { return this.createCommand; }
        }

        public string Name
        {
            get { return this.name; }
            set
            {
                this.name = value;
                this.OnPropertyChanged(() => Name);
            }
        }

        public string Phone
        {
            get { return this.phone; }
            set
            {
                this.phone = value;
                this.OnPropertyChanged(() => Phone);
            }
        }

        public string PostalCode
        {
            get { return this.postalCode; }
            set
            {
                this.postalCode = value;
                this.OnPropertyChanged(() => PostalCode);
            }
        }

        public string Street
        {
            get { return this.street; }
            set
            {
                this.street = value;
                this.OnPropertyChanged(() => Street);
            }
        }

        public string StreetNumber
        {
            get { return this.streetNumber; }
            set
            {
                this.streetNumber = value;
                this.OnPropertyChanged(() => StreetNumber);
            }
        }

        #endregion Properties

        #region Methods

        protected abstract void Create();

        private bool CanCreate()
        {
            return !string.IsNullOrWhiteSpace(this.Name); ;
        }

        #endregion Methods
    }
}